package com.example.myapplication6;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import java.text.SimpleDateFormat;

public class Step4Fragment extends Fragment {
    private Order order;

    public void setOrder(Order order) {
        this.order = order;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_step, container, false);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        LinearLayout llContent = view.findViewById(R.id.ll_content);
        Button btnSubmit = view.findViewById(R.id.btn_next);

        tvTitle.setText("步骤4：确认订单");
        btnSubmit.setText("提交订单");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String info = "巴士线路：" + order.busLine + "\n" +
                "乘车日期：" + sdf.format(order.rideDate) + "\n" +
                "乘客姓名：" + order.name + "\n" +
                "联系电话：" + order.phone;

        TextView tvInfo = new TextView(getContext());
        tvInfo.setText(info);
        tvInfo.setTextSize(16);
        llContent.addView(tvInfo);

        btnSubmit.setOnClickListener(v -> {
            ((MainActivity) getActivity()).submitOrderSuccess();
        });

        return view;
    }
}